package com.lb.jwitter.action;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;
import com.lb.jwitter.service.ConditionReport;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblDKMHDotDK;
import com.lb.jwitter.service.TblDKMHDotDKService;
import com.lb.jwitter.service.TblCTDTDMHocKyTrongNam;
import com.lb.jwitter.service.TblCTDTDMHocKyTrongNamService;

import com.lb.jwitter.service.TblCanBo;
import com.lb.jwitter.service.TblCanBoService;

import com.lb.jwitter.service.TblDKMHDotDK;
import com.lb.jwitter.service.TblDKMHDotDKService;

import com.lb.jwitter.service.TblDKMHAAOUrl;
import com.lb.jwitter.service.TblDKMHAAOUrlService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblDKMHDotDKEditFormAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private int id; 
    public int getId() { return id; }

    public void setId(int id) { this.id = id; }

    private TblDKMHDotDK tblDKMHDotDK; 
    public TblDKMHDotDK getTblDKMHDotDK() { 
        return tblDKMHDotDK; 
    } 
    private Collection<TblDKMHDotDK> tblDKMHDotDKs; 
    public Collection<TblDKMHDotDK>  getTblDKMHDotDKs() {
         return tblDKMHDotDKs; 
      } 

    private TblDKMHDotDKService tblDKMHDotDKService; 

    private Collection<TblCTDTDMHocKyTrongNam> tblCTDTDMHocKyTrongNams; 
    public Collection<TblCTDTDMHocKyTrongNam>  getTblCTDTDMHocKyTrongNams(){ 
              return tblCTDTDMHocKyTrongNams; 
     } 

    private TblCTDTDMHocKyTrongNamService tblCTDTDMHocKyTrongNamService; 

    private Collection<TblCanBo> tblCanBos; 
    public Collection<TblCanBo>  getTblCanBos(){ 
              return tblCanBos; 
     } 

    private TblCanBoService tblCanBoService; 

    private Collection<TblDKMHAAOUrl> tblDKMHAAOUrls; 
    public Collection<TblDKMHAAOUrl>  getTblDKMHAAOUrls(){ 
              return tblDKMHAAOUrls; 
     } 

    private TblDKMHAAOUrlService tblDKMHAAOUrlService; 

  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
       try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_DKMH_DotDK", "sua")){ 
        return "noprivilege"; 
    }
        tblDKMHDotDKService = (TblDKMHDotDKService) context.getBean("tbl_DKMH_DotDKClient"); 
        tblCTDTDMHocKyTrongNamService = (TblCTDTDMHocKyTrongNamService) context.getBean("tbl_CTDT_DM_HocKyTrongNamClient"); 

        tblCanBoService = (TblCanBoService) context.getBean("tbl_CanBoClient"); 


        tblDKMHAAOUrlService = (TblDKMHAAOUrlService) context.getBean("tbl_DKMH_AAOUrlClient"); 

        tblDKMHDotDK = tblDKMHDotDKService.gettblDKMHDotDK(new Long(id)); 
        

        List<ConditionReport> cons = new ArrayList<ConditionReport>();
        {
        	ConditionReport con = new ConditionReport();
        	con.setCol("id");
        	con.setValue1("desc");
        	con.setOperator("order");
        }
        
        tblCTDTDMHocKyTrongNams = tblCTDTDMHocKyTrongNamService.findtblCTDTDMHocKyTrongNamByCondition(cons, 20, 1);
        tblDKMHDotDKs = tblDKMHDotDKService.findtblDKMHDotDKByCondition(cons, 20, 1);


   if (pageSize == 0) 
   { 
       pageSize = 20; 
   } 
   if (page == 0) 
   { 
       page = 1; 
   } 

   cons.clear(); 
   if (id != 0) 
   { 
       ConditionReport con = new ConditionReport(); 
       con.setCol("dotDKId.id"); 
       con.setValue1(new Long(id)); 
       con.setOperator("eq"); 
       cons.add(con); 
   } 
   tblDKMHAAOUrls = tblDKMHAAOUrlService.findtblDKMHAAOUrlByCondition(cons, 0, 0); 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
      System.out.println("Loi EditForm tbl_DKMH_DotDK Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 } 
 } 
 
